#pragma once
struct bucket
{
	int cap;
	int water;
};

struct transfer
{
	int from;
	int to;
	int water;
};

#define BUCKET_COUNT 3
struct status
{
	void Init()
	{
		buckets[0].cap = 3;
		buckets[0].water = 0;

		buckets[1].cap = 5;
		buckets[1].water = 0;

		buckets[2].cap = 8;
		buckets[2].water = 8;
	}

	int GetKey()
	{
		return buckets[0].water * 100 + buckets[1].water * 10 + buckets[2].water;
	}

	int GetTransferWater(transfer t)
	{
		if (buckets[t.from].water == 0)
		{
			return 0;
		}
		if (buckets[t.to].water == buckets[t.to].cap)
		{
			return 0;
		}

		int targetLastCap = buckets[t.to].cap - buckets[t.to].water;
		if (buckets[t.from].water > targetLastCap)
		{
			return targetLastCap;
		}
		else
		{
			return buckets[t.from].water;
		}
	}

	void DoTransfer(transfer t)
	{
		buckets[t.from].water -= t.water;
		buckets[t.to].water += t.water;
	}

	bool IsDone()
	{
		return (buckets[1].water == 4 && buckets[2].water == 4);
	}

	bool equal(const status& other) const
	{
		for (int i = 0; i < BUCKET_COUNT; i++)
		{
			if (buckets[i].cap != other.buckets[i].cap
				|| buckets[i].water != other.buckets[i].water)
			{
				return false;
			}
			
		}
		return true;
	}

	bucket buckets[BUCKET_COUNT];
};

struct statusNode
{
	statusNode* parent;
	status s;
};